﻿#include "IndexWindow.h"
#include "IndexController.h"

static IndexWindow* rootWindow=nullptr;

IndexWindow::IndexWindow():navigation(nullptr){}

IndexWindow::~IndexWindow(){}

bool IndexWindow::init(){
	if(!CAWindow::init()){
		return false;
	}

	CANavigationController* subnavigation=new CANavigationController();
	subnavigation->setNavigationBarHidden(true, false);
	subnavigation->initWithRootViewController(IndexController::create());
	subnavigation->autorelease();
	CAVector<CAViewController*> views;
	views.pushBack(subnavigation);
	views.autorelease();
	CATabBarController* bar=new CATabBarController();
	bar->initWithViewControllers(views);
	bar->setTabBarHidden(true, false);
	bar->autorelease();
	navigation=new CANavigationController();
	navigation->initWithRootViewController(bar);
	navigation->setNavigationBarHidden(true, false);
	navigation->autorelease();
	this->setRootViewController(navigation);

	return true;
}

IndexWindow* IndexWindow::getInstance(){
	if(rootWindow==nullptr){
		rootWindow=new IndexWindow();
		rootWindow->init();
	}

	return rootWindow;
}

void IndexWindow::destroyInstance(){
	CC_SAFE_DELETE(rootWindow);
	rootWindow=nullptr;
}